package demo05

/**
 * @author xiaoZhao
 * @date 2022/7/1
 * @describe 扩展
 */
object Test17_Extends {
  def main(args: Array[String]): Unit = {
    // 1.类型的检测和转换
    val student: Student17 = new Student17("alice",13)
    student.sayHi()
    student.study()

    val person17: Person17 = new Student17("bob",14)
    person17.sayHi()

    println("student is Student17 :",student.isInstanceOf[Student17])
    println("student is Person17 :",student.isInstanceOf[Person17])
    println("person is Person17 :",person17.isInstanceOf[Person17])
    println("person is student :",person17.isInstanceOf[Student17])

    // 2.类型转换
    if (person17.isInstanceOf[Student17]){
      val newStudent = person17.asInstanceOf[Student17]
      newStudent.study()
    }

    println(classOf[Student17])

    println(WorkDay.MONDAY)
  }
}

class Person17(val name: String,val age: Int){
  def sayHi(): Unit ={
    println(" person hi from "+name)
  }
}

class Student17(name: String,age: Int) extends Person17(name,age){
  override def sayHi(): Unit = {
    println(" seudent hi from "+name)
  }

  def study(): Unit ={
    println(s" student study")
  }
}

// 定义枚举类
object WorkDay extends Enumeration{
  val MONDAY = Value(1,"星期一")
  val TUESDAY = Value(2,"星期二")
}

// 应用类
object TestApp extends App{
  println("app start")

  type MyString= String
  val a: MyString = "abc"
  println(a)
}